package grape.attend.rest.group.mvc;

import com.baomidou.mybatisplus.core.metadata.IPage;
import grape.attend.service.group.query.GroupListQuery;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.validation.Valid;
import grape.attend.rest.group.form.GroupCreateForm;
import grape.attend.rest.group.form.GroupUpdateForm;
import grape.attend.rest.group.form.GroupListPageForm;
import grape.attend.rest.group.vo.GroupVo;
import grape.attend.rest.group.mapper.GroupWebMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import grape.common.rest.mvc.BaseController;
import grape.attend.service.group.po.Group;
import grape.attend.service.group.api.IGroupService;
import java.util.List;
/**
 * <p>
 *  考勤组设置表 前端控制器
 * </p>
 *
 * @author yangwei
 * @since 2020-05-08
 */
@RestController
@RequestMapping("/attend/group")
@Api(tags = "考勤组设置相关接口")
public class GroupController extends BaseController<GroupVo, Group> {

    @Autowired
    private GroupWebMapper currentWebMapper;
    @Autowired
    private IGroupService currentService;



     @ApiOperation("添加考勤组设置")
     @PreAuthorize("hasAuthority('group:single:create')")
     @PostMapping
     @ResponseStatus(HttpStatus.CREATED)
     public GroupVo create(@RequestBody @Valid GroupCreateForm cf) {
         Group po = currentWebMapper.formToPo(cf);
         return super.create(po);
     }

     @ApiOperation("根据ID查询考勤组设置")
     @PreAuthorize("hasAuthority('group:single:queryById')")
     @GetMapping("/{id}")
     @ResponseStatus(HttpStatus.OK)
     public GroupVo queryById(@PathVariable String id) {
         return super.queryById(id);
     }

     @ApiOperation("删除考勤组设置")
     @PreAuthorize("hasAuthority('group:single:deleteById')")
     @DeleteMapping("/{id}")
     @ResponseStatus(HttpStatus.NO_CONTENT)
     public boolean deleteById(@PathVariable String id) {
         return super.deleteById(id);
     }

     @ApiOperation("更新考勤组设置")
     @PreAuthorize("hasAuthority('group:single:updateById')")
     @PutMapping("/{id}")
     @ResponseStatus(HttpStatus.CREATED)
     public GroupVo update(@PathVariable String id,@RequestBody @Valid GroupUpdateForm uf) {
         Group po = currentWebMapper.formToPo(uf);
         po.setId(id);
         return super.update(po);
     }

    @ApiOperation("分页查询考勤组设置")
    @PreAuthorize("hasAuthority('group:single:listPage')")
    @GetMapping("/listPage")
    @ResponseStatus(HttpStatus.OK)
    public IPage<GroupVo> listPage(GroupListPageForm listPageForm) {
         Group po = currentWebMapper.formToPo(listPageForm);
        GroupListQuery groupListQuery = new GroupListQuery();
        groupListQuery.setPoQuery(po);
        return super.listPage(groupListQuery,listPageForm);
     }

}
